package pers.jpa.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;
import pers.jpa.bean.User;
import pers.jpa.mapper.UserMapper;
import pers.jpa.service.UserService;

import java.util.List;

/**
 * @author
 * @date 2021/1/13 0013 - 下午 14:35
 */
@Service("userService")
public class UserServiceImp implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getAllByOther(Example example) {
        List<User> users = userMapper.findAll(example);
        return users;
    }

    @Override
    public Page<User> getPage(Integer pageNum, Integer pageLimit) {
        Pageable pageable = PageRequest.of(pageNum - 1,pageLimit);
        return userMapper.findAll(pageable);
    }

    @Override
    public Page<User> getPageSort(Integer pageNum, Integer pageLimit) {
        Sort sort = Sort.by(Sort.Direction.DESC,"old");
        Pageable pageable = PageRequest.of(pageNum - 1, pageLimit, sort);
        return userMapper.findAll(pageable);
    }

    @Override
    public void savaUser(User user) {
        userMapper.save(user);
    }

    @Override
    public List<User> findByNameLike(String name) {
        return userMapper.findByNameLike(name);
    }
}
